#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:1_insert_time.py
# author:张世航
# datetime:2024/11/9 22:28
# software: PyCharm
"""
this is function  description 
"""
# import module your need

# 1 定义一个10个元素的列表，通过列表自带的函数，实现元素在尾部插入和头部插入并记录程序运行的时间；用deque来实现，同样记录程序所耗费的时间；输出这2个时间的差值；
#     提示：列表原生的函数实现头部插入数据：list.insert(0, v)；list.append（2）)

import time
from collections import deque

# 定义一个10个元素的列表
my_list = [i for i in range(10)]

# 测试列表插入时间
start_time_list = time.time()
for i in range(5):
    my_list.insert(0, i)  # 头部插入
    my_list.append(i)      # 尾部插入
end_time_list = time.time()
list_time = end_time_list - start_time_list

# 测试 deque 插入时间
my_deque = deque([i for i in range(10)])
start_time_deque = time.time()
for i in range(5):
    my_deque.appendleft(i)  # 头部插入
    my_deque.append(i)      # 尾部插入
end_time_deque = time.time()
deque_time = end_time_deque - start_time_deque

# 输出时间差
print(f"List time: {list_time:.6f} seconds")
print(f"Deque time: {deque_time:.6f} seconds")
print(f"Time difference: {list_time - deque_time:.6f} seconds")